<?php
require ( "includes/config.php" );
require ( "includes/CGI.php" );
require ( "includes/SQL.php" );

$cgi = new CGI ();
$sql = new SQL ( $DBusername, $DBpassword, $server, $database );

if ( ! $sql->isConnected () )
{
  die ( $DatabaseError );
}

require ( "includes/CSQL.php" ); 
require ( "includes/lang/" . $language_pack . "/index.php" );

{
/************  FEATURED PROPERTY CONFIG  ***********/
$limit = "1"; // max number of featured properties to display
$columns = "1"; // number of columns of featuerd properties
/************  END FEATURED CONFIG  ***********/
$query = "
      SELECT
        p.id                AS id,
        p.propertyprice     AS propertyprice,
        p.propertyaddress   AS propertyaddress,
        pl.propertylocation AS propertylocation,
        ps.propertystatus   AS propertystatus,
        pt.propertytype     AS propertytype,
        p.propertyref       AS propertyref,
        p.propertybedrooms  AS propertybedrooms,
        p.propertybathrooms  AS propertybathrooms,
        p.propertyphoto1    AS propertyphoto1,
        p.shortdescription  AS shortdescription,
        p.featuredproperty  AS featuredproperty,
        p.longdescription   AS longdescription
      FROM
        " . $property_table . " p
        INNER JOIN
        " . $propertytypes_table . " pt ON (p.propertytype=pt.id)
        INNER JOIN
        " . $propertylocations_table . " pl ON (p.propertylocation=pl.id)
        INNER JOIN
        " . $propertystatus_table . " ps ON (p.propertystatus=ps.id)
      WHERE
        p.propertyshow='1' AND featuredproperty='Y'
      ";

 
    // set the query ordering
    if ( isset ( $property_search_order ) && $property_search_order != "" )
      $query .= "ORDER BY p." . $property_search_order . " " .
           ( "a" == strtolower ( substr ( $property_search_ordering, 0, 1 ) ) ?
             "ASC" : "DESC" );
    
    $results = $sql->execute ( $query, SQL_RETURN_ASSOC );
    $total_results = sizeof ( $results );
    $total_pages = ceil ( $total_results / $limit ); //total number of pages
    $page = $cgi->getValue ( "page" );

    if ( ! $page )
      $page = 1;
      
    $offset = ( $page - 1 ) * $limit; //starting number for displaying results out of DB 
    $max = $offset + $limit;
    $max = ( $max > $total_results ? $total_results : $max );
    

     $cli_query = mysql_query($query);
     $cli_num = mysql_num_rows($cli_query);
    for ( $l = $offset; $l < $max; ++$l )
    { 
      $row = $results [ $l ];


if($cli_num > 0) { //
	  $x=0;
echo "<table width=\"95%\" border=\"0\" align=\"center\"><tr>";
  	  	
  while($cli = mysql_fetch_array($cli_query)) {
  $Price = number_format ($cli [ 'propertyprice' ], 2, ",", "."); 
$x=$x+1;

if ($x % $columns == 0) {

      // Start of Display Output
  $Price = number_format ($cli [ 'propertyprice' ], 2, ",", "."); 
echo "<td align=\"center\" width=\"50%\" valign=\"top\">
<p>";
 if ($cli [ 'propertyphoto1' ] ){ echo "<a href=\"$template_page_name?op=mi&id=$cli[id]\"><IMG SRC=\"".$ImageURL."$cli[propertyphoto1]\" BORDER=\"0\" WIDTH=\"195\" HEIGHT=\"140\"></a>";}
 else { echo "<a href=\"$template_page_name?op=mi&id=$cli[id]\"><IMG SRC=\"".$ImageURL."nopropertyimage.jpg\" BORDER=\"0\" WIDTH=\"195\" HEIGHT=\"140\"></a>";}

echo "<br>$cli[propertyaddress] $cli[propertylocation]<br><b>".CURRENCY."$Price</b></p></td>";
echo "</tr><tr>";
}else{

echo "<td align=\"center\" width=\"50%\" valign=\"top\">
<p>";
 if ($cli [ 'propertyphoto1' ] ){ echo "<a href=\"$template_page_name?op=mi&id=$cli[id]\"><IMG SRC=\"".$ImageURL."$cli[propertyphoto1]\" BORDER=\"0\" WIDTH=\"195\" HEIGHT=\"140\"></a>";}
 else { echo "<a href=\"$template_page_name?op=mi&id=$cli[id]\"><IMG SRC=\"".$ImageURL."nopropertyimage.jpg\" BORDER=\"0\" WIDTH=\"195\" HEIGHT=\"140\"></a>";}

echo "<br>$cli[propertyaddress] $cli[propertylocation]<br><b>".CURRENCY."$Price</b></p></td>";

}

}//end while

echo "</tr></table>";
}//end if num >0    

    }  
}

    ?>